import { Prisma } from '@prisma/client';
import { Transform, Type } from 'class-transformer';
import { IsDefined, IsNotEmptyObject, ValidateNested } from 'class-validator';
import { BaseDto, BaseFindDto, BaseQueryDto, WhiteListItem } from './base.dto';

export class CardCreateDto extends BaseDto<Prisma.CardCreateInput> {}

export class CardUpdateDto extends BaseDto<Prisma.CardUpdateInput> {
  @IsDefined({ message: '条件必填' })
  @IsNotEmptyObject({ nullable: false }, { message: '条件参数必填' })
  where: Prisma.CardWhereUniqueInput;
}

export class CardFindDto extends BaseFindDto<
  Prisma.CardWhereUniqueInput,
  Prisma.CardSelect
> {}

export class CardQueryDto extends BaseQueryDto<Prisma.CardWhereUniqueInput> {}

export class CardListDto extends BaseQueryDto<Prisma.CardWhereUniqueInput> {}

export class CardRemoveDto {
  @IsDefined({ message: 'ID必填' })
  @Transform(({ value }) => Number(value))
  id: number;
}

export class CardAirdropDto {
  @IsDefined({ message: 'ID必填' })
  @Transform(({ value }) => Number(value))
  id: number;

  @IsDefined({ message: '空投记录必填' })
  @ValidateNested({ each: true })
  @Type(() => WhiteListItem)
  rows: WhiteListItem[];
}
